package com.blackcat.monitor.vo;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;

import com.blackcat.monitor.vo.annotation.FieldCode;

public class DataTemplete {

	String nodeId;

	HashMap<String, Method> methods = new HashMap<String, Method>();

	// List<String> data;

	public DataTemplete() {
		FieldCode fc;
		for (Method med : this.getClass().getMethods()) {
			if (med.getAnnotation(FieldCode.class) != null) {
				fc = med.getAnnotation(FieldCode.class);
				methods.put(fc.value(), med);
			}
		}

	}



	public String getNodeId() {
		return nodeId;
	}



	public void setNodeId(String nodeId) {
		this.nodeId = nodeId;
	}



	public void setValue(String infoNum, String infoValue) {
		try {
			methods.get(infoNum).invoke(this, infoValue);
		} catch (IllegalArgumentException e) {
			System.out.println("查询结果数据信息值异常");
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			System.out.println("VO对象写入值异常");
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			System.out.println("VO对象调用异常");
			e.printStackTrace();
		}
	}
}
